package service.impl;

import java.util.ArrayList;
import java.util.List;

import dao.FoodDao;
import dao.FoodTypeDao;
import dao.impl.FoodDaoImpl;
import dao.impl.FoodTypeDaoImpl;
import pojo.Food;
import pojo.FoodType;
import service.FoodListManager;

public class FoodListManagerImpl implements FoodListManager{

	private FoodTypeDao foodTypeDao;
	private FoodDao foodDao;

	
	public FoodListManagerImpl() {
		foodTypeDao = new FoodTypeDaoImpl();
		foodDao = new FoodDaoImpl();
	}

	@Override
	public List<FoodType> loadFoodType(){
		try{
			List<FoodType> fl=  foodTypeDao.findAllFoodTypes();
			if(fl==null){
				fl = new ArrayList<FoodType>();
			}
			fl.add(0,new FoodType("1","所有"));
			return fl;
		}catch(Exception e){
			return null;
		}
	}

	@Override
	public List<Food> loadFoodList(String mid, String typeId) {
		if(typeId==null || typeId.equals("1")){
			return foodDao.findAllFoods(mid, 0, 1);
		}else{
			return foodDao.findAllFoods(mid, typeId, 0, 1);
		}
	}

	@Override
	public List<String> findAllMerchantIdByFoodTypeId(String tid) {
		return foodDao.findAllMerchantIdByFoodTypeId(tid);
	}

	@Override
	public List<Food> findAllFoods(String mid) {
		return foodDao.findAllFoods(mid, 0, 1);
	}
}
